{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Check if Strings Can be Made Equal With Operations II"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Medium"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #hash-table #string #sorting"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #哈希表 #字符串 #排序"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: checkStrings"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #判断通过操作能否让字符串相等 II"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你两个字符串&nbsp;<code>s1</code>&nbsp;和&nbsp;<code>s2</code>&nbsp;，两个字符串长度都为&nbsp;<code>n</code>&nbsp;，且只包含&nbsp;<strong>小写&nbsp;</strong>英文字母。</p>\n",
    "\n",
    "<p>你可以对两个字符串中的 <strong>任意一个</strong>&nbsp;执行以下操作 <strong>任意</strong>&nbsp;次：</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>选择两个下标&nbsp;<code>i</code> 和&nbsp;<code>j</code>&nbsp;，满足 <code>i &lt; j</code>&nbsp;且 <code>j - i</code>&nbsp;是 <strong>偶数</strong>，然后 <strong>交换</strong> 这个字符串中两个下标对应的字符。</li>\n",
    "</ul>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p>如果你可以让字符串<em>&nbsp;</em><code>s1</code><em> </em>和<em>&nbsp;</em><code>s2</code>&nbsp;相等，那么返回 <code>true</code>&nbsp;，否则返回 <code>false</code>&nbsp;。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong class=\"example\">示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<b>输入：</b>s1 = \"abcdba\", s2 = \"cabdab\"\n",
    "<b>输出：</b>true\n",
    "<b>解释：</b>我们可以对 s1 执行以下操作：\n",
    "- 选择下标 i = 0 ，j = 2 ，得到字符串 s1 = \"cbadba\" 。\n",
    "- 选择下标 i = 2 ，j = 4 ，得到字符串 s1 = \"cbbdaa\" 。\n",
    "- 选择下标 i = 1 ，j = 5 ，得到字符串 s1 = \"cabdab\" = s2 。\n",
    "</pre>\n",
    "\n",
    "<p><strong class=\"example\">示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<b>输入：</b>s1 = \"abe\", s2 = \"bea\"\n",
    "<b>输出：</b>false\n",
    "<b>解释：</b>无法让两个字符串相等。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>n == s1.length == s2.length</code></li>\n",
    "\t<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>\n",
    "\t<li><code>s1</code> 和&nbsp;<code>s2</code>&nbsp;只包含小写英文字母。</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [check-if-strings-can-be-made-equal-with-operations-ii](https://leetcode.cn/problems/check-if-strings-can-be-made-equal-with-operations-ii/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [check-if-strings-can-be-made-equal-with-operations-ii](https://leetcode.cn/problems/check-if-strings-can-be-made-equal-with-operations-ii/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"abcdba\"\\n\"cabdab\"', '\"abe\"\\n\"bea\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        # 奇偶分组，俩者分组要相等\n",
    "        n = len(s1)\n",
    "        s1odd = [0 for _ in range(26)]\n",
    "        s1even = [0 for _ in range(26)]\n",
    "        s2odd = [0 for _ in range(26)]\n",
    "        s2even = [0 for _ in range(26)]\n",
    "        for i in range(0,n,2):\n",
    "            s1even[ord(s1[i]) - ord('a')] += 1\n",
    "            s2even[ord(s2[i]) - ord('a')] += 1\n",
    "        for i in range(1,n,2):\n",
    "            s1odd[ord(s1[i]) - ord('a')] += 1\n",
    "            s2odd[ord(s2[i]) - ord('a')] += 1\n",
    "        return s1odd == s2odd and s1even == s2even"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "         return Counter(s1[::2]) == Counter(s2[::2]) and Counter(s1[1::2]) == Counter(s2[1::2])\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        from collections import Counter\n",
    "    \n",
    "        cnt_s1_jishu = Counter(s1[0:len(s1):2])\n",
    "        cnt_s1_oushu = Counter(s1[1:len(s1):2])\n",
    "\n",
    "\n",
    "        cnt_s2_jishu = Counter(s2[0:len(s1):2])\n",
    "        cnt_s2_oushu = Counter(s2[1:len(s1):2])\n",
    "\n",
    "        \n",
    "        if cnt_s1_jishu == cnt_s2_jishu and cnt_s1_oushu == cnt_s2_oushu:\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        d10,d11,d20,d21 = {},{},{},{}\n",
    "        for i in range(len(s1)):\n",
    "            if i%2 == 1:\n",
    "                if s1[i] in d11:\n",
    "                    d11[s1[i]] += 1\n",
    "                else:\n",
    "                    d11[s1[i]] = 1\n",
    "            else:\n",
    "                if s1[i] in d10:\n",
    "                    d10[s1[i]] += 1\n",
    "                else:\n",
    "                    d10[s1[i]] = 1\n",
    "        for i in range(len(s2)):\n",
    "            if i%2 == 1:\n",
    "                if s2[i] in d21:\n",
    "                    d21[s2[i]] += 1\n",
    "                else:\n",
    "                    d21[s2[i]] = 1\n",
    "            else:\n",
    "                if s2[i] in d20:\n",
    "                    d20[s2[i]] += 1\n",
    "                else:\n",
    "                    d20[s2[i]] = 1\n",
    "        \n",
    "        for k in d10:\n",
    "            if k not in d20 or d10[k] != d20[k]:\n",
    "                return False\n",
    "        for k in d11:\n",
    "            if k not in d21 or d11[k] != d21[k]:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        s1_even = defaultdict(int)\n",
    "        s1_odd = defaultdict(int)\n",
    "\n",
    "        s2_even = defaultdict(int)\n",
    "        s2_odd = defaultdict(int)\n",
    "\n",
    "        for i in range(len(s1)):\n",
    "            if i % 2 == 0:\n",
    "                s1_even[s1[i]] += 1\n",
    "                s2_even[s2[i]] += 1\n",
    "            else:\n",
    "                s1_odd[s1[i]] += 1\n",
    "                s2_odd[s2[i]] += 1\n",
    "        return s1_even == s2_even and s1_odd == s2_odd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        n1, n2 = len(s1), len(s2)\n",
    "        odd_pos_char_cnts = Counter()\n",
    "        even_pos_char_cnts = Counter()\n",
    "        if n1 != n2:\n",
    "            return False\n",
    "        for i,c in enumerate(s1):\n",
    "            if i % 2 == 0:\n",
    "                even_pos_char_cnts[c] += 1\n",
    "            else:\n",
    "                odd_pos_char_cnts[c] += 1\n",
    "                \n",
    "        for i, c in enumerate(s2):\n",
    "            if i % 2 == 0:\n",
    "                even_pos_char_cnts[c] -= 1\n",
    "            else:\n",
    "                odd_pos_char_cnts[c] -= 1 \n",
    "                \n",
    "        for k, v in even_pos_char_cnts.items():\n",
    "            if v != 0:\n",
    "                return False\n",
    "        for k,v in odd_pos_char_cnts.items():\n",
    "            if v != 0:\n",
    "                return False\n",
    "        return True\n",
    "        \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        s1_even = defaultdict(int)\n",
    "        s1_odd = defaultdict(int)\n",
    "\n",
    "        s2_even = defaultdict(int)\n",
    "        s2_odd = defaultdict(int)\n",
    "\n",
    "        for i in range(len(s1)):\n",
    "            if i % 2 == 0:\n",
    "                s1_even[s1[i]] += 1\n",
    "                s2_even[s2[i]] += 1\n",
    "            else:\n",
    "                s1_odd[s1[i]] += 1\n",
    "                s2_odd[s2[i]] += 1\n",
    "        return s1_even == s2_even and s1_odd == s2_odd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        d1,d2={},{}\n",
    "        n=len(s1)\n",
    "        for i in range(0,n,2):\n",
    "            d1[s1[i]]=d1.get(s1[i],0)+1\n",
    "            d2[s2[i]]=d2.get(s2[i],0)+1\n",
    "        d3,d4={},{}\n",
    "        for i in range(1,n,2):\n",
    "            d3[s1[i]]=d3.get(s1[i],0)+1\n",
    "            d4[s2[i]]=d4.get(s2[i],0)+1\n",
    "        return d1 == d2 and d3 == d4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        return Counter(s1[::2]) == Counter(s2[::2]) and Counter(s1[1::2]) == Counter(s2[1::2])\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    pass\n",
    "    print(Solution.checkStrings(None, \"abcd\", \"dacb\"))\n",
    "    pass\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        return Counter(s1[::2]) == Counter(s2[::2]) and Counter(s1[1::2]) == Counter(s2[1::2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        hashmap1 = Counter()\n",
    "        hashmap2 = Counter()\n",
    "        hashmap3 = Counter()\n",
    "        hashmap4 = Counter()\n",
    "        for i in range(0, len(s1), 2):\n",
    "            hashmap1[s1[i]] += 1\n",
    "            hashmap2[s2[i]] += 1\n",
    "        for j in range(1, len(s1), 2):\n",
    "            hashmap3[s1[j]] += 1\n",
    "            hashmap4[s2[j]] += 1\n",
    "        print(hashmap1)\n",
    "        print(hashmap2)\n",
    "        print(hashmap3)\n",
    "        print(hashmap4)\n",
    "        return hashmap1 == hashmap2 and hashmap3 == hashmap4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        arr1 = [0] * 26\n",
    "        arr2 = [0] * 26\n",
    "        arr3 = [0] * 26\n",
    "        arr4 = [0] * 26\n",
    "        \n",
    "        for i in range(0, len(s1), 2):\n",
    "            arr1[ord(s1[i]) - ord('a')] += 1\n",
    "            arr2[ord(s2[i]) - ord('a')] += 1\n",
    "\n",
    "        for i in range(1, len(s1), 2):\n",
    "            arr3[ord(s1[i]) - ord('a')] += 1\n",
    "            arr4[ord(s2[i]) - ord('a')] += 1\n",
    "\n",
    "        for i in range(26):\n",
    "            if arr1[i] != arr2[i] or arr3[i] != arr4[i]:\n",
    "                return False\n",
    "\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        hashmap1 = Counter()\n",
    "        hashmap2 = Counter()\n",
    "        hashmap3 = Counter()\n",
    "        hashmap4 = Counter()\n",
    "        for i in range(0, len(s1), 2):\n",
    "            hashmap1[s1[i]] += 1\n",
    "            hashmap2[s2[i]] += 1\n",
    "        for j in range(1, len(s1), 2):\n",
    "            hashmap3[s1[j]] += 1\n",
    "            hashmap4[s2[j]] += 1\n",
    "        print(hashmap1)\n",
    "        print(hashmap2)\n",
    "        print(hashmap3)\n",
    "        print(hashmap4)\n",
    "        return hashmap1 == hashmap2 and hashmap3 == hashmap4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        s1d,s1s,s2d,s2s=dict(),dict(),dict(),dict()\n",
    "        for i in range(len(s1)):\n",
    "            if i%2:\n",
    "                if s1[i] in s1d :s1d[s1[i]]+=1\n",
    "                else: s1d[s1[i]]=1\n",
    "\n",
    "                if s2[i] in s2d :s2d[s2[i]]+=1\n",
    "                else: s2d[s2[i]]=1\n",
    "            else:\n",
    "                if s1[i] in s1s :s1s[s1[i]]+=1\n",
    "                else: s1s[s1[i]]=1\n",
    "\n",
    "                if s2[i] in s2s :s2s[s2[i]]+=1\n",
    "                else: s2s[s2[i]]=1\n",
    "        if s1d==s2d and s1s==s2s:return True\n",
    "        return False\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        d1 = collections.Counter(list(s1[::2]))\n",
    "        d2 = collections.Counter(list(s2[::2]))\n",
    "        d = d1 - d2\n",
    "        for key in d:\n",
    "            if d[key] != 0:\n",
    "                return False\n",
    "        d1 = collections.Counter(list(s1[1::2]))\n",
    "        d2 = collections.Counter(list(s2[1::2]))\n",
    "        d = d1 - d2\n",
    "        for key in d:\n",
    "            if d[key] != 0:\n",
    "                return False       \n",
    "        return True "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import math\n",
    "from typing import List\n",
    "from collections import deque, defaultdict\n",
    "from sortedcontainers import SortedList\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        \"\"\"\n",
    "\n",
    "        :param s1:\n",
    "        :param s2:\n",
    "        :return:\n",
    "        \"\"\"\n",
    "\n",
    "        m1 = defaultdict(int)\n",
    "        m2 = defaultdict(int)\n",
    "        for i in s1:\n",
    "            m1[i] += 1\n",
    "        for i in s2:\n",
    "            m2[i] += 1\n",
    "        for i in m1:\n",
    "            v2 = m2.get(i, 0)\n",
    "            if m1[i] != v2:\n",
    "                return False\n",
    "        for i in m2:\n",
    "            v1 = m1.get(i, 0)\n",
    "            if m2[i] != v1:\n",
    "                return False\n",
    "\n",
    "        m1odd = defaultdict(int)\n",
    "        m1even = defaultdict(int)\n",
    "        m2odd = defaultdict(int)\n",
    "        m2even = defaultdict(int)\n",
    "\n",
    "        for k,v in enumerate(s1):\n",
    "            if k %2 == 0:\n",
    "                m1odd[v] += 1\n",
    "            else:\n",
    "                m1even[v] += 1\n",
    "        for k,v in enumerate(s2):\n",
    "            if k %2 == 0:\n",
    "                m2odd[v] += 1\n",
    "            else:\n",
    "                m2even[v] += 1\n",
    "\n",
    "        for i in m1odd:\n",
    "            v = m2odd.get(i, 0)\n",
    "            if m1odd[i] != v:\n",
    "                return False\n",
    "\n",
    "        for i in m2odd:\n",
    "            v = m1odd.get(i, 0)\n",
    "            if m2odd[i] != v:\n",
    "                return False\n",
    "\n",
    "        for i in m1even:\n",
    "            v = m2even.get(i, 0)\n",
    "            if m1even[i] != v:\n",
    "                return False\n",
    "\n",
    "        for i in m2even:\n",
    "            v = m1even.get(i, 0)\n",
    "            if m2even[i] != v:\n",
    "                return False\n",
    "        \n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        n = len(s1)\n",
    "        ss1 = ''\n",
    "        ss2 = ''\n",
    "        for i in range(0, n, 2):\n",
    "            ss1 += s1[i]\n",
    "            ss2 += s2[i]\n",
    "\n",
    "        ss3 = ''\n",
    "        ss4 = ''\n",
    "        for i in range(1, n, 2):\n",
    "            ss3 += s1[i]\n",
    "            ss4 += s2[i]\n",
    "        \n",
    "        return Counter(ss1) == Counter(ss2) and Counter(ss3) == Counter(ss4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        if collections.Counter(s1) != collections.Counter(s2):\n",
    "            return False\n",
    "        if collections.Counter([c for c in s1[::2]]) != collections.Counter([c for c in s2[::2]]):\n",
    "            return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        n = len(s1)\n",
    "        odd_dic, even_dic = Counter(), Counter()\n",
    "        for index, ch in enumerate(s1):\n",
    "            if index % 2 == 0:\n",
    "                even_dic[ch] += 1\n",
    "            else:\n",
    "                odd_dic[ch] += 1\n",
    "        res = \"\"\n",
    "        index = 0\n",
    "        while index < n:\n",
    "            if index % 2 == 0:\n",
    "                if even_dic[s2[index]] > 0:\n",
    "                    res += s2[index]\n",
    "                    even_dic[s2[index]] -= 1\n",
    "                else:\n",
    "                    return False\n",
    "            else:\n",
    "                if odd_dic[s2[index]] > 0:\n",
    "                    res += s2[index]\n",
    "                    odd_dic[s2[index]] -= 1\n",
    "                else:\n",
    "                    return False\n",
    "            index += 1\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:        \n",
    "        for i in range(0, 2):\n",
    "            a = ''.join(sorted(s1[i::2]))\n",
    "            b = ''.join(sorted(s2[i::2]))            \n",
    "            if a != b: return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        s1_even = ''.join(sorted(s1[::2]))\n",
    "        s1_odd = ''.join(sorted(s1[1::2]))\n",
    "        s2_even = ''.join(sorted(s2[::2]))\n",
    "        s2_odd = ''.join(sorted(s2[1::2]))\n",
    "        return s1_even == s2_even and s1_odd == s2_odd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        from collections import Counter\n",
    "        return Counter([s1[i] for i in range(len(s1)) if i % 2 == 0]) == Counter([s2[i] for i in range(len(s2)) if i % 2 == 0]) and Counter([s1[i] for i in range(len(s1)) if i % 2 == 1]) == Counter([s2[i] for i in range(len(s2)) if i % 2 == 1])\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        return sorted(s1[::2]) == sorted(s2[::2]) and sorted(s1[1::2]) == sorted(s2[1::2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        s1_even = ''.join(sorted(s1[::2]))\n",
    "        s1_odd = ''.join(sorted(s1[1::2]))\n",
    "        s2_even = ''.join(sorted(s2[::2]))\n",
    "        s2_odd = ''.join(sorted(s2[1::2]))\n",
    "        return s1_even == s2_even and s1_odd == s2_odd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        return str(sorted(s1[::2])) == str(sorted(s2[::2])) and str(sorted(s1[1::2])) == str(sorted(s2[1::2]))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        return sorted(s1[::2]) == sorted(s2[::2]) and sorted(s1[1::2]) == sorted(s2[1::2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        odd_1 = s1[::2]\n",
    "        odd_2 = s2[::2]\n",
    "        even_1 = s1[1::2]\n",
    "        even_2 = s2[1::2]\n",
    "\n",
    "        return sorted(odd_1) == sorted(odd_2) and sorted(even_1) == sorted(even_2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        return sorted(s1[::2]) == sorted(s2[::2]) and sorted(s1[1::2]) == sorted(s2[1::2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        return sorted(s1[::2]) == sorted(s2[::2]) and sorted(s1[1::2]) == sorted(s2[1::2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        return sorted(s1[::2]) == sorted(s2[::2]) and sorted(s1[1::2]) == sorted(s2[1::2])\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        return sorted(s1[::2]) == sorted(s2[::2]) and sorted(s1[1::2]) == sorted(s2[1::2])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        return sorted(s1[::2]) == sorted(s2[::2]) and sorted(s1[1::2]) == sorted(s2[1::2])\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        return sorted(s1[::2]) == sorted(s2[::2]) and sorted(s1[1::2]) == sorted(s2[1::2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        n1, n2 = len(s1), len(s2)\n",
    "        return sorted(s1[0:n1:2]) == sorted(s2[0:n2:2]) and sorted(s1[1:n1:2]) == sorted(s2[1:n2:2])\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        s1 = s1[::2] + s1[1::2]\n",
    "        s2 = s2[::2] + s2[1::2]\n",
    "        mid = len(s1) // 2 + (len(s1) % 2)\n",
    "        print(s1)\n",
    "        print(s2)\n",
    "        return sorted(s1[:mid]) == sorted(s2[:mid]) and sorted(s1[mid:]) == sorted(s2[mid:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        def f(s):\n",
    "            s1 = [s[i] for i in range(0,len(s),2)]\n",
    "            s2 = [s[i] for i in range(1,len(s),2)]\n",
    "            return Counter(s1),Counter(s2)\n",
    "        c1,c2 = f(s1)\n",
    "        d1,d2 = f(s2)\n",
    "        return c1==d1 and c2==d2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "\n",
    "        def pack(s):\n",
    "            a = ''.join(sorted([c for i,c in enumerate(s) if i&1==1]))\n",
    "            b = ''.join(sorted([c for i,c in enumerate(s) if i&1==0]))\n",
    "            return a+b\n",
    "        \n",
    "        return pack(s1)==pack(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        a = ''\n",
    "        b = ''\n",
    "        c = ''\n",
    "        d = ''\n",
    "        for i in range(len(s1)):\n",
    "            if i % 2:\n",
    "                a += s1[i]\n",
    "                c += s2[i]\n",
    "            else:\n",
    "                b += s1[i]\n",
    "                d += s2[i]\n",
    "        return sorted(a) == sorted(c) and sorted(b) == sorted(d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        f = lambda x: x\n",
    "        return sorted(s1[::2], key=f) == sorted(s2[::2], key=f) and sorted(s1[1::2], key=f) == sorted(s2[1::2], key=f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        f = lambda x: x\n",
    "        return sorted(s1[::2], key=f) == sorted(s2[::2], key=f) and sorted(s1[1::2], key=f) == sorted(s2[1::2], key=f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        arr1 = [0] * 26\n",
    "        arr2 = [0] * 26\n",
    "        arr3 = [0] * 26\n",
    "        arr4 = [0] * 26\n",
    "        s1=list(s1)\n",
    "        s2=list(s2)\n",
    "        n=len(s1)\n",
    "        for i in range(0,n,2):\n",
    "            arr1[ord(s1[i])-ord('a')]+=1\n",
    "            arr2[ord(s2[i])-ord('a')]+=1\n",
    "        for i in range(1,n,2):\n",
    "            arr3[ord(s1[i])-ord('a')]+=1\n",
    "            arr4[ord(s2[i])-ord('a')]+=1\n",
    "        for i in range(26):\n",
    "            if arr1[i]!=arr2[i] or arr3[i]!=arr4[i]:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        l1 = sorted(s1[0::2])\n",
    "        l2 = sorted(s1[1::2])\n",
    "        l3 = sorted(s2[0::2])\n",
    "        l4 = sorted(s2[1::2])\n",
    "        return l1 == l3 and l2 == l4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        \n",
    "        j1, o1 = \"\", \"\"\n",
    "        j2, o2 = \"\", \"\"\n",
    "        for i in range(len(s1)):\n",
    "            if i % 2 == 0:\n",
    "                o1 += s1[i]\n",
    "                o2 += s2[i]\n",
    "            else:\n",
    "                j1 += s1[i]\n",
    "                j2 += s2[i]\n",
    "        if sorted(j1) == sorted(j2) and sorted(o1) == sorted(o2):\n",
    "            return True\n",
    "        return False\n",
    "            \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    d = {}\n",
    "    def __init__(self):\n",
    "        self.d = {}\n",
    "\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        l1 = []\n",
    "        l2 = []\n",
    "        for i in range(0, len(s1), 2):\n",
    "            l1.append(s1[i])\n",
    "            l2.append(s2[i])\n",
    "\n",
    "        l1.sort()\n",
    "        l2.sort()\n",
    "        # print(l1, l2)\n",
    "        for i in range(len(l1)):\n",
    "            if l1[i] != l2[i]:\n",
    "                return False\n",
    "        \n",
    "        l1 = []\n",
    "        l2 = []\n",
    "        for i in range(1, len(s1), 2):\n",
    "            l1.append(s1[i])\n",
    "            l2.append(s2[i])\n",
    "\n",
    "        l1.sort()\n",
    "        l2.sort()\n",
    "        for i in range(len(l1)):\n",
    "            if l1[i] != l2[i]:\n",
    "                return False\n",
    "        \n",
    "        return True\n",
    "        \n",
    "        if s1 in self.d:\n",
    "            return self.d[s1]\n",
    "\n",
    "        # print(s1, s2)\n",
    "        if s1 == s2:\n",
    "            self.d[s1] = True\n",
    "            return True\n",
    "        \n",
    "        for i in range(len(s1)):\n",
    "            if s1[i] == s2[i]:\n",
    "                continue\n",
    "            \n",
    "            # 找到不一样的字母了，开始从s1的后面找和当前s2一样的字母\n",
    "            for j in range(i, len(s1)):\n",
    "                if s1[j] == s2[i] and (j-i)%2== 0:\n",
    "                    ti = s1[i]\n",
    "                    tj = s1[j]\n",
    "                    ts1 = s1[:i] + tj + s1[i+1:j] + ti + s1[j+1:]\n",
    "                    # print(s1, i,j,ts1)\n",
    "                    r = self.checkStrings(ts1, s2)\n",
    "                    if r == True:\n",
    "                        self.d[s1] = True\n",
    "                        return True\n",
    "            self.d[s1] = False\n",
    "            return False\n",
    "                    \n",
    "        self.d[s1] = False\n",
    "        return False\n",
    "                    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        s11=sorted(s1[::2])\n",
    "        s12=sorted(s1[1::2])\n",
    "        s21=sorted(s2[::2])\n",
    "        s22=sorted(s2[1::2])\n",
    "        return s11==s21 and s12==s22"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "\n",
    "        def pack(s):\n",
    "            a,b = [],[]\n",
    "            for i,c in enumerate(s):\n",
    "                if i&1==1:\n",
    "                    a.append(c)\n",
    "                else:\n",
    "                    b.append(c)\n",
    "            return ''.join(sorted(a))+''.join(sorted(b))\n",
    "        \n",
    "        return pack(s1)==pack(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        # 提取奇数和偶数位置的字符\n",
    "        s1_odd, s1_even = s1[1::2], s1[0::2]\n",
    "        s2_odd, s2_even = s2[1::2], s2[0::2]\n",
    "\n",
    "        # 对字符进行排序\n",
    "        s1_odd, s1_even = sorted(s1_odd), sorted(s1_even)\n",
    "        s2_odd, s2_even = sorted(s2_odd), sorted(s2_even)\n",
    "\n",
    "        # 比较奇数和偶数位置字符\n",
    "        return s1_odd == s2_odd and s1_even == s2_even\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        t1 = list(s1[::2])\n",
    "        t1.sort()\n",
    "        t2 = list(s1[1::2])\n",
    "        t2.sort()\n",
    "        w1 = list(s2[::2])\n",
    "        w1.sort()\n",
    "        w2 = list(s2[1::2])\n",
    "        w2.sort()\n",
    "        return t1 == w1 and t2 == w2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        s3, s4 = list(s1[::2]), list(s1[1::2])\n",
    "        s5, s6 = list(s2[::2]), list(s2[1::2])\n",
    "        s3.sort()\n",
    "        s5.sort()\n",
    "        if s3 != s5:\n",
    "            return False\n",
    "        s4.sort()\n",
    "        s6.sort()\n",
    "        if s4 != s6:\n",
    "            return False\n",
    "        return True\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    print(Solution().checkStrings(\"abcdba\", \"cabdab\"), True)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        return sorted(s1[:]) == sorted(s2[:]) and sorted(s1[1::2]) == sorted(s2[1::2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        n=len(s1)\n",
    "        o1=[s1[i] for i in range(1,n,2)]\n",
    "        e1=[s1[i] for i in range(0,n,2)]\n",
    "        o2=[s2[i] for i in range(1,n,2)]\n",
    "        e2=[s2[i] for i in range(0,n,2)]\n",
    "        return Counter(o1)==Counter(o2) and Counter(e1)==Counter(e2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from math import *\n",
    "import math\n",
    "from typing import List\n",
    "from collections import Counter, deque, defaultdict\n",
    "from bisect import *\n",
    "from heapq import heappop, heappush, heapify\n",
    "from functools import lru_cache\n",
    "from itertools import accumulate, product\n",
    "from sortedcontainers import SortedList, SortedDict\n",
    "import copy\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        def getP(s):\n",
    "            l1 = []\n",
    "            l2 = []\n",
    "            for i, c in enumerate(s):\n",
    "                if i % 2:\n",
    "                    l1.append(c)\n",
    "                else:\n",
    "                    l2.append(c)\n",
    "\n",
    "            return ''.join(sorted(l1)) + ''.join(sorted(l2))\n",
    "\n",
    "        return getP(s1) == getP(s2)\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        n=len(s1)\n",
    "        l=[[[] for _ in range(2)] for _ in range(2)]\n",
    "        for i,s in enumerate((s1,s2)):\n",
    "            for j in range(2):\n",
    "                l[i][j]=[s[k] for k in range(j,n,2)]\n",
    "                l[i][j].sort()\n",
    "        return l[0]==l[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        n = len(s1)\n",
    "        def go(s):\n",
    "            f = [[], []]\n",
    "            for i in range(n):\n",
    "                f[i & 1].append(s[i])\n",
    "            f[0].sort()\n",
    "            f[1].sort()\n",
    "            return f\n",
    "        f1 = go(s1)\n",
    "        f2 = go(s2)\n",
    "        return f1[0] == f2[0] and f1[1] == f2[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        n = len(s1)\n",
    "        ss1 = sorted([s1[i] for i in range(0, n, 2)])\n",
    "        ss2 = sorted([s1[i] for i in range(1, n, 2)])\n",
    "        ss3 = sorted([s2[i] for i in range(0, n, 2)])\n",
    "        ss4 = sorted([s2[i] for i in range(1, n, 2)])\n",
    "        return ''.join(ss1) == ''.join(ss3) and ''.join(ss2) == ''.join(ss4)\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        n=len(s1)\n",
    "        s10=sorted([s1[i] for i in range(n) if i%2==0])\n",
    "        s11=sorted([s1[i] for i in range(n) if i%2==1])\n",
    "        s20=sorted([s2[i] for i in range(n) if i%2==0])\n",
    "        s21=sorted([s2[i] for i in range(n) if i%2==1])\n",
    "        return s10==s20 and s11==s21"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        t1,t2 = [],[]\n",
    "        for i in range(len(s1)):\n",
    "            if i%2==0:\n",
    "                t1.append(s1[i])\n",
    "            else:\n",
    "                t2.append(s1[i])\n",
    "        t3,t4 = [],[]\n",
    "        for i in range(len(s2)):\n",
    "            if i%2==0:\n",
    "                t3.append(s2[i])\n",
    "            else:\n",
    "                t4.append(s2[i])\n",
    "        t1.sort()\n",
    "        t2.sort()\n",
    "        t3.sort()\n",
    "        t4.sort()\n",
    "        if t1==t3 and t2==t4:\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        \n",
    "        even_chars_1 = sorted([c for idx, c in enumerate(s1) if idx % 2 == 0])\n",
    "        odd_chars_1 = sorted([c for idx, c in enumerate(s1) if idx % 2 == 1])\n",
    "        even_chars_2 = sorted([c for idx, c in enumerate(s2) if idx % 2 == 0])\n",
    "        odd_chars_2 = sorted([c for idx, c in enumerate(s2) if idx % 2 == 1])\n",
    "         \n",
    "        return even_chars_1 == even_chars_2 and odd_chars_1 == odd_chars_2\n",
    "        \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        \n",
    "        a = []\n",
    "        b = []\n",
    "        x = []\n",
    "        y = []\n",
    "        for i in range(len(s1)):\n",
    "            if i % 2 == 0:\n",
    "                a.append(s1[i])\n",
    "            else:\n",
    "                b.append(s1[i])\n",
    "        for i in range(len(s1)):\n",
    "            if i % 2 == 0:\n",
    "                x.append(s2[i])\n",
    "            else:\n",
    "                y.append(s2[i])\n",
    "        a.sort()\n",
    "        b.sort()\n",
    "        x.sort()\n",
    "        y.sort()\n",
    "        res = a == x and b == y\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        s11 = s1[::2]\n",
    "        s12 = s1[1::2]\n",
    "        s21 = s2[::2]\n",
    "        s22 = s2[1::2]\n",
    "        s11 = tuple(sorted(list(s11)))\n",
    "        s12 = tuple(sorted(list(s12)))\n",
    "        s21 = tuple(sorted(list(s21)))\n",
    "        s22 = tuple(sorted(list(s22)))\n",
    "        return s11 == s21 and s12 == s22"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        n = len(s1)\n",
    "        a = sorted(s1[:n:2])\n",
    "        a += sorted(s1[1:n:2])\n",
    "        \n",
    "        b = sorted(s2[:n:2])\n",
    "        b += sorted(s2[1:n:2])\n",
    "        return a == b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        ji = []\n",
    "        ou = []\n",
    "        for i, x in enumerate(s1):\n",
    "            if i & 1:\n",
    "                ji.append(x)\n",
    "            else:\n",
    "                ou.append(x)\n",
    "        ji.sort()\n",
    "        ou.sort()\n",
    "        j1 = []\n",
    "        o1 = []\n",
    "        for i, x in enumerate(s2):\n",
    "            if i & 1:\n",
    "                j1.append(x)\n",
    "            else:\n",
    "                o1.append(x)\n",
    "        j1.sort()\n",
    "        o1.sort()\n",
    "        return ''.join(ji) == ''.join(j1) and ''.join(ou) == ''.join(o1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "      res1 = []\n",
    "      res2 = []\n",
    "      for i in range(26):\n",
    "        temp = []\n",
    "        res1.append(temp)\n",
    "      for i in range(26):\n",
    "        temp = []\n",
    "        res2.append(temp)\n",
    "      for i in range(len(s1)):\n",
    "        res1[ord(s1[i]) - 97].append(i % 2 + 1)\n",
    "      for i in range(len(s1)):\n",
    "        res2[ord(s2[i]) - 97].append(i % 2 + 1)\n",
    "      for i in range(len(res1)):\n",
    "        if sum(res1[i]) != sum(res2[i]):\n",
    "          return False\n",
    "          break\n",
    "      return True\n",
    "      \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        s1 = list(s1)\n",
    "        s1[::2] = sorted(s1[::2])\n",
    "        s1[1::2] = sorted(s1[1::2])\n",
    "        s2 = list(s2)\n",
    "        s2[::2] = sorted(s2[::2])\n",
    "        s2[1::2] = sorted(s2[1::2])        \n",
    "        return s1 == s2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "\n",
    "        n = len(s1)\n",
    "        c1,c2 = [],[]\n",
    "        t1,t2 = [],[]\n",
    "        for i in range(n):\n",
    "            if (i+1)%2:\n",
    "                c1.append(s1[i])\n",
    "                t1.append(s2[i])\n",
    "            else:\n",
    "                c2.append(s1[i])\n",
    "                t2.append(s2[i])\n",
    "        c1.sort()\n",
    "        c2.sort()\n",
    "        t1.sort()\n",
    "        t2.sort()\n",
    "        return (c1==t1) and (c2==t2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        a=[]\n",
    "        b=[]\n",
    "        c=[]\n",
    "        d=[]\n",
    "        n=len(s1)\n",
    "        if n%2==0:\n",
    "            for i in range(0,n,2):\n",
    "                a.append(s1[i])\n",
    "                c.append(s2[i])\n",
    "                b.append(s1[i+1])\n",
    "                d.append(s2[i+1])\n",
    "        else:\n",
    "            for i in range(0,n-1,2):\n",
    "                a.append(s1[i])\n",
    "                c.append(s2[i])\n",
    "                b.append(s1[i+1])\n",
    "                d.append(s2[i+1])\n",
    "            a.append(s1[-1])\n",
    "            c.append(s2[-1])\n",
    "        a.sort()\n",
    "        b.sort()\n",
    "        c.sort()\n",
    "        d.sort()\n",
    "        flag1=flag2=False\n",
    "        for i in range(len(a)):\n",
    "            if a[i]!=c[i]:\n",
    "                flag1=True\n",
    "                break\n",
    "        if flag1:\n",
    "            for i in range(len(a)):\n",
    "                if a[i]!=c[-1-i]:\n",
    "                    flag2=True\n",
    "        if flag1 and flag2:\n",
    "            return False\n",
    "        flag1=flag2=False\n",
    "        for i in range(len(b)):\n",
    "            if b[i]!=d[i]:\n",
    "                flag1=True\n",
    "                break\n",
    "        if flag1:\n",
    "            for i in range(len(b)):\n",
    "                if b[i]!=d[-1-i]:\n",
    "                    flag2=True\n",
    "        if flag1 and flag2:\n",
    "            return False\n",
    "        return True\n",
    "\n",
    "\n",
    "\n",
    "        \n",
    "        \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        evenS1, oddS1 = [], []\n",
    "        evenS2, oddS2 = [], []\n",
    "        n = len(s1)\n",
    "        for i in range(n):\n",
    "            if not i%2:\n",
    "                evenS1.append(s1[i])\n",
    "                evenS2.append(s2[i])\n",
    "            else:\n",
    "                oddS1.append(s1[i])\n",
    "                oddS2.append(s2[i])\n",
    "        \n",
    "        evenS1.sort()\n",
    "        evenS2.sort()\n",
    "        oddS1.sort()\n",
    "        oddS2.sort()\n",
    "        for ch1, ch2 in zip(evenS1, evenS2):\n",
    "            if ch1!=ch2:\n",
    "                return False\n",
    "        for ch1, ch2 in zip(oddS1, oddS2):\n",
    "            if ch1!=ch2:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        odd1 = []\n",
    "        odd2 = []\n",
    "        even1 = []\n",
    "        even2 = []\n",
    "        for i in range(len(s1)):\n",
    "            if i % 2:\n",
    "                odd1.append(s1[i])\n",
    "            else:\n",
    "                even1.append(s1[i])\n",
    "        for i in range(len(s2)):\n",
    "            if i % 2:\n",
    "                odd2.append(s2[i])\n",
    "            else:\n",
    "                even2.append(s2[i])\n",
    "        odd1 = sorted(odd1)\n",
    "        odd2 = sorted(odd2)\n",
    "        even1 = sorted(even1)\n",
    "        even2 = sorted(even2)\n",
    "        for i in range(len(odd1)):\n",
    "            if odd1[i] != odd2[i]:\n",
    "                return False\n",
    "        for i in range(len(even1)):\n",
    "            if even1[i] != even2[i]:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        def oddEven(s):\n",
    "            odd = []\n",
    "            even = []\n",
    "            for i in range(len(s)):\n",
    "                if i % 2 == 0:\n",
    "                    even.append(s[i])\n",
    "                else:\n",
    "                    odd.append(s[i])\n",
    "            return sorted(odd), sorted(even)\n",
    "        \n",
    "        odd1, even1 = oddEven(s1)\n",
    "        odd2, even2 = oddEven(s2)\n",
    "        return odd1 == odd2 and even1 == even2\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        length = len(s1)\n",
    "        a = []\n",
    "        b = []\n",
    "        c = []\n",
    "        d = []\n",
    "        for i in range(length):\n",
    "            if i%2==0:\n",
    "                a.append(s1[i])\n",
    "                c.append(s2[i])\n",
    "            else:\n",
    "                b.append(s1[i])\n",
    "                d.append(s2[i])\n",
    "        a.sort()\n",
    "        b.sort()\n",
    "        c.sort()\n",
    "        d.sort()\n",
    "        return a==c and b == d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        q1=[]\n",
    "        q2=[]\n",
    "        q3=[]\n",
    "        q4=[]\n",
    "        lon=len(s1)\n",
    "        for i in range(lon):\n",
    "            if i%2==0:\n",
    "                q1.append(s1[i])\n",
    "                q2.append(s2[i])\n",
    "            else:\n",
    "                q3.append(s1[i])\n",
    "                q4.append(s2[i])\n",
    "        q1.sort()\n",
    "        q2.sort()\n",
    "        q3.sort()\n",
    "        q4.sort()\n",
    "        if q1==q2 and q3==q4:\n",
    "            return True\n",
    "        return False\n",
    "        \n",
    "                \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1)!=len(s2):\n",
    "            return False\n",
    "        s1j=[]\n",
    "        s1o=[]\n",
    "        s2j=[]\n",
    "        s2o=[]        \n",
    "        for i in range(len(s1)):\n",
    "            if i%2==0:\n",
    "                s1o.append(s1[i])\n",
    "                s2o.append(s2[i])\n",
    "            else:\n",
    "                s1j.append(s1[i])\n",
    "                s2j.append(s2[i])\n",
    "        s1j.sort()\n",
    "        s1o.sort()\n",
    "        s2j.sort()\n",
    "        s2o.sort()\n",
    "        return s1j==s2j and s1o==s2o"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:   \n",
    "        cache1 = [[]*2 for _ in range(2)]\n",
    "        cache2 = [[]*2 for _ in range(2)]\n",
    "\n",
    "        n = len(s1)\n",
    "        for i in range(n):\n",
    "            cache1[i%2].append(s1[i])\n",
    "            cache2[i%2].append(s2[i])\n",
    "        cache1[0].sort()\n",
    "        cache1[1].sort()\n",
    "        cache2[0].sort()\n",
    "        cache2[1].sort()\n",
    "        if cache1[0] == cache2[0] and cache1[1] == cache2[1]:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        ou1 = []\n",
    "        ji1 = []\n",
    "        ou2 = []\n",
    "        ji2 = []\n",
    "        \n",
    "        n = len(s1)\n",
    "        \n",
    "        for i in range(n):\n",
    "            if i % 2 == 0:\n",
    "                ou1.append(s1[i])\n",
    "                ou2.append(s2[i])\n",
    "            else:\n",
    "                ji1.append(s1[i])\n",
    "                ji2.append(s2[i])\n",
    "                \n",
    "        ou1.sort()\n",
    "        ou2.sort()\n",
    "        ji1.sort()\n",
    "        ji2.sort()\n",
    "        \n",
    "        return ou1==ou2 and ji1==ji2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        os1,os2,es1,es2=[],[],[],[]\n",
    "        for i in range(0,len(s1)):\n",
    "            if i%2==0:\n",
    "                os1.append(s1[i])\n",
    "                os2.append(s2[i])\n",
    "            else:\n",
    "                es1.append(s1[i])\n",
    "                es2.append(s2[i])\n",
    "        os1.sort()\n",
    "        os2.sort()\n",
    "        es1.sort()\n",
    "        es2.sort()\n",
    "        return \"\".join(os1)==\"\".join(os2) and \"\".join(es1)==\"\".join(es2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        s1_even =  []\n",
    "        s1_odd = []\n",
    "\n",
    "        s2_even = []\n",
    "        s2_odd = []\n",
    "\n",
    "        for i in range(len(s1)):\n",
    "            if i % 2 == 0:\n",
    "                s1_even.append(s1[i])\n",
    "                s2_even.append(s2[i])\n",
    "            else:\n",
    "                s1_odd.append(s1[i])\n",
    "                s2_odd.append(s2[i])\n",
    "        return sorted(s1_even) == sorted(s2_even) and sorted(s1_odd) == sorted(s2_odd)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        def equalList(l1: List, l2: List) -> bool:\n",
    "            s1_dict = {}\n",
    "            s2_dict = {}\n",
    "            if len(l1) != len(l2):\n",
    "                return False\n",
    "            else:\n",
    "                for i in range(len(l1)):\n",
    "                    ch1 = l1[i]\n",
    "                    ch2 = l2[i]\n",
    "                    if ch1 not in s1_dict:\n",
    "                        s1_dict[ch1] = 0\n",
    "                    if ch2 not in s2_dict:\n",
    "                        s2_dict[ch2] = 0\n",
    "                    s1_dict[ch1] += 1\n",
    "                    s2_dict[ch2] += 1\n",
    "            if s1_dict == s2_dict:\n",
    "                return True\n",
    "            else:\n",
    "                return False\n",
    "\n",
    "        evenS1 = []\n",
    "        oddS1 = []\n",
    "        evenS2 = []\n",
    "        oddS2= []\n",
    "        for i in range(len(s1)):\n",
    "            if i % 2 == 0:\n",
    "                evenS1.append(s1[i])\n",
    "                evenS2.append(s2[i])\n",
    "            else:\n",
    "                oddS1.append(s1[i])\n",
    "                oddS2.append(s2[i])\n",
    "        if equalList(evenS1, evenS2) and equalList(oddS1, oddS2):\n",
    "            return True\n",
    "        else:\n",
    "            return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def checkStrings(self, s1: str, s2: str) -> bool:\n",
    "        s1_even =  []\n",
    "        s1_odd = []\n",
    "\n",
    "        s2_even = []\n",
    "        s2_odd = []\n",
    "\n",
    "        for i in range(len(s1)):\n",
    "            if i % 2 == 0:\n",
    "                s1_even.append(s1[i])\n",
    "                s2_even.append(s2[i])\n",
    "            else:\n",
    "                s1_odd.append(s1[i])\n",
    "                s2_odd.append(s2[i])\n",
    "        return sorted(s1_even) == sorted(s2_even) and sorted(s1_odd) == sorted(s2_odd)"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
